<?php

?>

<html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            
            <!-- LIBRERIAS JQUERY PARA LA CREACION DE LAS ALERTAS -->
        <script type="text/javascript" src="../../../Ginecobstetricia/vista/js/alertify.js"></script>
        <link rel="stylesheet" href="../../../Ginecobstetricia/vista/css/alertify.core.css" />
        <link rel="stylesheet" href="../../../Ginecobstetricia/vista/css/alertify.default.css" />
      
        <script type="text/javascript" src="../../../Laboratorio/vista/datepicker/jquery-1.10.2.min.js"></script>
        <script type="text/javascript" src="../../../Laboratorio/vista/datepicker/jquery-ui.min.js"></script>
        <script type="text/javascript" src="../../../Laboratorio/vista/datepicker/jquery-ui-timepicker-addon.js"></script>
        <script type="text/javascript" src="../../../Laboratorio/vista/datepicker/jquery-ui-sliderAccess.js"></script>
        <link rel="stylesheet" media="all" type="text/css" href="../../../Laboratorio/vista/datepicker/jquery-ui.css" />
	<link rel="stylesheet" media="all" type="text/css" href="../../../Laboratorio/vista/datepicker/jquery-ui-timepicker-addon.css" />
        
         
            <style type="text/css">
                label,input,button,select,textarea{font-size:14px;font-weight:normal;line-height:20px}input,button,select,textarea{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif}label{display:block;margin-bottom:5px}select,textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{display:inline-block;height:28px;padding:4px 6px;margin-bottom:10px;font-size:14px;line-height:20px;color:#555;vertical-align:middle;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}input,textarea,.uneditable-input{width:170px}textarea{height:auto}textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{background-color:#fff;border:1px solid #ccc;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border linear .2s,box-shadow linear .2s;-moz-transition:border linear .2s,box-shadow linear .2s;-o-transition:border linear .2s,box-shadow linear .2s;transition:border linear .2s,box-shadow linear .2s}textarea:focus,input[type="text"]:focus,input[type="password"]:focus,input[type="datetime"]:focus,input[type="datetime-local"]:focus,input[type="date"]:focus,input[type="month"]:focus,input[type="time"]:focus,input[type="week"]:focus,input[type="number"]:focus,input[type="email"]:focus,input[type="url"]:focus,input[type="search"]:focus,input[type="tel"]:focus,input[type="color"]:focus,.uneditable-input:focus{border-color:rgba(82,168,236,0.8);outline:0;outline:thin dotted \9;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6)}input[type="radio"],input[type="checkbox"]{margin:4px 0 0;margin-top:1px \9;*margin-top:0;line-height:normal}input[type="file"],input[type="image"],input[type="submit"],input[type="reset"],input[type="button"],input[type="radio"],input[type="checkbox"]{width:auto}select,input[type="file"]{height:30px;*margin-top:4px;line-height:30px}select{width:170px;background-color:#fff;border:1px solid #ccc}select[multiple],select[size]{height:auto}select:focus,input[type="file"]:focus,input[type="radio"]:focus,input[type="checkbox"]:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.uneditable-input,.uneditable-textarea{color:#999;cursor:not-allowed;background-color:#fcfcfc;border-color:#ccc;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.025);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.025);box-shadow:inset 0 1px 2px rgba(0,0,0,0.025)}.uneditable-input{overflow:hidden;white-space:nowrap}.uneditable-textarea{width:auto;height:auto}input:-moz-placeholder,textarea:-moz-placeholder{color:#999}input:-ms-input-placeholder,textarea:-ms-input-placeholder{color:#999}input::-webkit-input-placeholder,textarea::-webkit-input-placeholder{color:#999}.radio,.checkbox{min-height:20px;padding-left:20px}.radio input[type="radio"],.checkbox input[type="checkbox"]{float:left;margin-left:-20px}.controls>.radio:first-child,.controls>.checkbox:first-child{padding-top:5px}.radio.inline,.checkbox.inline{display:inline-block;padding-top:5px;margin-bottom:0;vertical-align:middle}.radio.inline+.radio.inline,.checkbox.inline+.checkbox.inline{margin-left:10px}.input-mini{width:60px}.input-small{width:90px}.input-medium{width:150px}.input-large{width:210px}.input-xlarge{width:270px}.input-xxlarge{width:530px}input[class*="span"],select[class*="span"],textarea[class*="span"],.uneditable-input[class*="span"],.row-fluid input[class*="span"],.row-fluid select[class*="span"],.row-fluid textarea[class*="span"],.row-fluid .uneditable-input[class*="span"]{float:none;margin-left:0}.input-append input[class*="span"],.input-append .uneditable-input[class*="span"],.input-prepend input[class*="span"],.input-prepend .uneditable-input[class*="span"],.row-fluid input[class*="span"],.row-fluid select[class*="span"],.row-fluid textarea[class*="span"],.row-fluid .uneditable-input[class*="span"],.row-fluid .input-prepend [class*="span"],.row-fluid .input-append [class*="span"]{display:inline-block}input,textarea,.uneditable-input{margin-left:0}.controls-row [class*="span"]+[class*="span"]{margin-left:20px}input.span12,textarea.span12,.uneditable-input.span12{width:926px}input.span11,textarea.span11,.uneditable-input.span11{width:846px}input.span10,textarea.span10,.uneditable-input.span10{width:766px}input.span9,textarea.span9,.uneditable-input.span9{width:686px}input.span8,textarea.span8,.uneditable-input.span8{width:606px}input.span7,textarea.span7,.uneditable-input.span7{width:526px}input.span6,textarea.span6,.uneditable-input.span6{width:446px}input.span5,textarea.span5,.uneditable-input.span5{width:366px}input.span4,textarea.span4,.uneditable-input.span4{width:286px}input.span3,textarea.span3,.uneditable-input.span3{width:206px}input.span2,textarea.span2,.uneditable-input.span2{width:126px}input.span1,textarea.span1,.uneditable-input.span1{width:46px}.controls-row{*zoom:1}.controls-row:before,.controls-row:after{display:table;line-height:0;content:""}.controls-row:after{clear:both}.controls-row [class*="span"],.row-fluid .controls-row [class*="span"]{float:left}.controls-row .checkbox[class*="span"],.controls-row .radio[class*="span"]{padding-top:5px}input[disabled],select[disabled],textarea[disabled],input[readonly],select[readonly],textarea[readonly]{cursor:not-allowed;background-color:#eee}input[type="radio"][disabled],input[type="checkbox"][disabled],input[type="radio"][readonly],input[type="checkbox"][readonly]{background-color:transparent}.control-group.warning .control-label,.control-group.warning .help-block,.control-group.warning .help-inline{color:#c09853}.control-group.warning .checkbox,.control-group.warning .radio,.control-group.warning input,.control-group.warning select,.control-group.warning textarea{color:#c09853}.control-group.warning input,.control-group.warning select,.control-group.warning textarea{border-color:#c09853;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.control-group.warning input:focus,.control-group.warning select:focus,.control-group.warning textarea:focus{border-color:#a47e3c;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e;-moz-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e}.control-group.warning .input-prepend .add-on,.control-group.warning .input-append .add-on{color:#c09853;background-color:#fcf8e3;border-color:#c09853}

                #t{
                    font-size: 15px;
                    background-color: #E2ECEE;
                    border-radius: 10px;
                    margin: auto;
                    border: 1px solid #CED5D7;
                    border-radius: 20px;
                    padding: 30px 30px 18px;
                    margin-top: 2px;
                    background-color: white;
                    box-shadow: 0px 5px 10px #B5C1C5, 0 0 0 10px #EEF5F7 inset;
                    width: 20%
                }
                
                
                #titulo {
                    font-size: 18px;
                    color: #323133;
                    font-family: Helvetica Neue, Arial, Helvetica, sans-serif;
                    letter-spacing: -1px;
                    text-decoration: none; 
                    text-shadow: 1px 1px #fff, 0 0 #0e0e0e, 2px 3px 1px #e3e3e3; 
                    text-transform: none; 
                    word-spacing: -2px;
                }
                .white {
                    border-radius: 5px;
                    color: #606060;
                    border: solid 1px #b7b7b7;
                    background: #fff;
                    background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ededed));
                    background: -moz-linear-gradient(top,  #fff,  #ededed);
                    filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed');
                    padding: 3px 3px 3px;
                    font-size: 95%;
                    margin-top: -5px;
            }
            .white:hover {
                    background: #ededed;
                    background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#dcdcdc));
                    background: -moz-linear-gradient(top,  #fff,  #dcdcdc);
                    filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#dcdcdc');
            }
            .white:active {
                    color: #999;
                    background: -webkit-gradient(linear, left top, left bottom, from(#ededed), to(#fff));
                    background: -moz-linear-gradient(top,  #ededed,  #fff);
                    filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#ffffff');
                
            }
            #tabs, #ui-datepicker-div, .ui-datepicker{ font-size: 80%; }
            </style>
            <script>
                function calendario(){
                $( "#basic_example_4" ).datepicker({ 
                     autoSize: true,
                     dayNames: ['Domingo', 'Lunes', 'Martes', 'Mi?rcoles', 'Jueves', 'Viernes', 'S?bado'],
                     dayNamesMin: ['Dom', 'Lu', 'Ma', 'Mi', 'Je', 'Vi', 'Sa'],
                     firstDay: 1,
                     monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
                     monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],
                     dateFormat: 'dd-mm-yy',
                     changeMonth: true,
                     changeYear: true,
                     yearRange: "-90:+0"

                    });
                    
                } 
                $(function(){
                    $('#tabs').tabs();

                    $('.example-container > pre').each(function(i){
                            eval($(this).text());
                    });
            });
         
         /*validar campos de la asignacion de cita*/
            function validar(){
                if ($("#basic_example_4").val()===""){
                alertify.alert("Seleccione Fecha"), function () {
                    $("#basic_example_4").focus();
                };
                return false;
                
            }  if ($("#hora").val()===""){
                alertify.alert("Digite Hora"), function () {
                    $("#hora").focus();
                };
                return false;
                
            }  if ($("#minuto").val()===""){
                alertify.alert("Digite Minutos"), function () {
                    $("#minuto").focus();
                };
                return false;
                
            }if ($("#obser").val()===""){
                alertify.alert("Digite Observaciones"), function () {
                    $("#obser").focus();
                };
                return false;
            }
            confirmar();
            }
            
            /*confirmar asignacion de cita*/
            function confirmar(){
                    alertify.confirm("<p>¿Esta seguro de asignar la cita?</p>", function (e) {
				if (e) {
                                    guardar();
				} else { 
                                    $("").focus();
				}
				}); 
                                return false;
                }
                
                /*guardar datos de la asignacion*/
            function guardar(){
                var oid = $("#OID").val();
                var fec = $("#basic_example_4").val();
                var obs = $("#obser").val();
                var hor = $("#hora").val();
                var min = $("#minuto").val();
                var hora = hor+':'+min;
                var fecha = fec+' '+hora;
                $.ajax ({
                type: "POST",
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                url: "../../controlador/php/sql/asigCita.php",
                data: {oid:oid,fec:fec,obs:obs,hora:hora,fecha:fecha},
                success: guarda,
                timeout: 4000            
                });
            }
            
            function guarda(respu){
                if(respu.n == 1){
                    alertify.error("Ocurrio Un Error, Debe Autenticarse Nuevamente.");
                }else{
                    window.opener.asignar();
                    window.close();
                }
            }
            function datos(){
                var oid = $("#OID").val();
                
                $.ajax ({
                type: "POST",
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                url: "../../controlador/php/sql/asig.php",
                data: {oid:oid},
                success: datos2,
                timeout: 4000 
                });
            }
            function datos2(respu){
                rpt = $.parseJSON(respu);
                for (dat in rpt) {
                    var hora = rpt[dat].asighora;
                    var elem = hora.split(':');
                    var hor = elem[0];
                    var min = elem[1];
                    document.getElementById("obser").value = rpt[dat].asigobserv;
                    document.getElementById("oida").value =  rpt[dat].oid;
                    var fecha = rpt[dat].asigfecha;
                    if (fecha == ""){
                        var fecha2 = rpt[dat].asigfecha2;
                        var eleme = fecha2.split(' ');
                        var m = eleme[0];
                        var d = eleme[1];
                        var a = eleme[2];
                        var horas1 = eleme[3];
                        var horas2 = eleme[4];
                        if(horas1 == ""){
                             var ho = horas2;
                        }else{
                             ho = horas1;
                        }
                        var elemen = ho.split(':');
                        var horas = elemen[0];
                        var minu = elemen[1];
                        var j = minu;
                        var elemet = j.split('');
                        var o = elemet[0];
                        var o2 = elemet[1];
                        var ab = elemet[2];
                        var b = elemet[3];
                        document.getElementById("basic_example_4").value = m+' '+d+' '+a;
                        document.getElementById("hora").value = horas;
                        document.getElementById("minuto").value = o+''+o2;
                        document.getElementById("horadia").innerHTML = ab+''+b;
                    }else{
                        document.getElementById("basic_example_4").value = rpt[dat].asigfecha;
                        document.getElementById("hora").value = hor;
                        document.getElementById("minuto").value = min;
                    }
                    
                   
                }
            }
            function validar2(){
                if ($("#basic_example_4").val()===""){
                alertify.alert("Seleccione Fecha"), function () {
                    $("#basic_example_4").focus();
                };
                return false;
                
            }  if ($("#hora").val()===""){
                alertify.alert("Digite Hora"), function () {
                    $("#hora").focus();
                };
                return false;
                
            }  if ($("#minuto").val()===""){
                alertify.alert("Digite Minutos"), function () {
                    $("#minuto").focus();
                };
                return false;
                
            }if ($("#obser").val()===""){
                alertify.alert("Digite Observaciones"), function () {
                    $("#obser").focus();
                };
                return false;
            }
            confirmarE();
            }
            function confirmarE(){
                    alertify.confirm("<p>¿Esta seguro de editar la cita?</p>", function (e) {
				if (e) {
                                    editar();
				} else { 
                                    $("").focus();
				}
				}); 
                                return false;
                }
            function editar(){
               var oid = $("#OID").val();
                var fec = $("#basic_example_4").val();
                var obs = $("#obser").val();
                var hor = $("#hora").val();
                var min = $("#minuto").val();
                var hora = hor+':'+min;
                var fecha = fec+' '+hora;
                $.ajax ({
                type: "POST",
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                url: "../../controlador/php/sql/ediCita.php",
                data: {oid:oid,fec:fec,obs:obs,hora:hora,fecha:fecha},
                success: edita,
                timeout: 4000 
                });
            }
            function edita(){
               var oid = $("#OID").val();
                window.opener.asignar(oid);
                window.close();
            }
            function boton(){
                var oida = $("#oida").val();
                if(oida == ""){
                    document.getElementById("boton").innerHTML ='<input type="button" value="Asignar" class="white" onclick="validar();"/>';
                }else{
                    document.getElementById("boton").innerHTML =' <input type="button" value="Editar" class="white" onclick="validar2();"/>';
                }
            }
            
            (function(a){a.fn.validCampoFranz=function(b)
                {a(this).on({keypress:function(a)
                        {var c=a.which,d=a.keyCode,e=String.fromCharCode(c).toLowerCase(),f=b;(-1!=f.indexOf(e)||9==d||37!=c&&37==d||39==d&&39!=c||8==d||46==d&&46!=c)&&161!=c||a.preventDefault()}})}})(jQuery);

            $(function(){
                $('#hora').validCampoFranz('0123456789');
                $('#minuto').validCampoFranz('0123456789');


            });
            
            function validarHora(){
                h = document.getElementById("hora");
                if(h.value > 23){
                    alertify.alert("<font size=2>ERROR, FORMATO 24/H", function () {
                            h.focus();
                    });
                }
            }
            function validarMinuto(){
                h = document.getElementById("minuto");
                if(h.value > 59){
                    alertify.alert("<font size=2>ERROR, FORMATO", function () {
                            h.focus();
                    });
                }
            }
            </script>
        </head>
        <body onload="datos(); calendario();">
            <table width="100%">
                    <tr>
                        <td align="center">
                            <b>ASIGNAR CITA</b>
                        </td>
                    </tr>
                </table>
            <table id="t" >
                    <tr>
                        <td>
                            Fecha:
                        </td>
                        <td>
                            <input type="text" name="basic_example_4[]" id="basic_example_4" value="" style="width: 50%"/>
                  
                            <input type="text" name="" value="" id="hora" style="width: 17%" maxlength="2" onchange="validarHora();"/> <b>:</b>
                      
                            <input type="text" name="" value="" id="minuto" style="width: 17%" maxlength="2" onchange="validarMinuto();"/>
                          
                        </td>
                        <td>
                            <div id="horadia"></div>
                        </td>
                        
                    </tr>
                    <tr>
                        <td>
                            Observacion:
                        </td>
                        <td colspan="2">
                            <textarea name="" rows="4" cols="30" id="obser" style="margin: 2px 0px 10px; height: 90px; width: 200px;"></textarea>
                        </td>
                    </tr>
                </table>
            <br>
            <table width="100%" style="font-size: 80%">
                <tr>
                    <td align="center">
                        <input type="button" value="Asignar" class="white" onclick="validar();"/>
                    </td>
                </tr>
                <input type="hidden" id="OID" name="txtOID" value="<?php echo$_REQUEST['OID'] ?>" />
                <input type="hidden" id="oida" name="txtoid" value="" />
            </table>
        </body>
</html>
